namespace DotNetNuke.Modules.Admin.ResourceInstaller
{
    using System;
    using System.Collections;
    using System.IO;

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The PaDnnInstaller_V2Provider extends PaDnnInstallerBase to support V2 Providers
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// [cnurse]	04/21/2005  documented
    /// </history>
    /// -----------------------------------------------------------------------------
    public class PaDnnInstaller_V2Provider : PaDnnInstallerBase
    {
        public PaDnnInstaller_V2Provider(PaInstallInfo InstallerInfo) : base(InstallerInfo)
        {
        }

        protected override void CreateFiles(PaFolder Folder)
        {
            IEnumerator refObjectHelperL0=null;
            this.InstallerInfo.Log.StartJob(base.FILES_Creating);
            string binFolder = Path.Combine(this.InstallerInfo.SitePath, "bin");
            string rootFolder = Path.Combine(this.InstallerInfo.SitePath, Path.Combine("Providers", Path.Combine(Folder.ProviderType, Folder.Name)));
            if (!Directory.Exists(rootFolder))
            {
                Directory.CreateDirectory(rootFolder);
            }
            try
            {
                refObjectHelperL0 = Folder.Files.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    PaFile file = (PaFile) refObjectHelperL0.Current;
                    if ((file.Type != PaFileType.DataProvider) && (file.Type != PaFileType.Other))
                    {
                    }
                    if (((file.Type == PaFileType.Sql) ? 1 : 0) != 0)
                    {
                        string fileFolder = Path.Combine(rootFolder, file.Path);
                        if (!Directory.Exists(fileFolder))
                        {
                            Directory.CreateDirectory(fileFolder);
                        }
                        string FullFileName = Path.Combine(fileFolder, file.Name);
                        this.CreateFile(FullFileName, file.Buffer);
                        this.InstallerInfo.Log.AddInfo(base.FILE_Created + FullFileName);
                    }
                    else if (file.Type == PaFileType.Dll)
                    {
                        string binFullFileName = Path.Combine(binFolder, file.Name);
                        this.CreateFile(binFullFileName, file.Buffer);
                        this.InstallerInfo.Log.AddInfo(base.FILE_Created + binFullFileName);
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            this.InstallerInfo.Log.EndJob(base.FILES_Created);
        }

        public override void Install(PaFolderCollection folders)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = folders.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    PaFolder folder = (PaFolder) refObjectHelperL0.Current;
                    this.CreateFiles(folder);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }
    }
}

